/*
 * BackupServiceDAO.java
 *
 * Created on March 26, 2007, 8:47 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.group1E.data;

import edu.byu.isys413.group1E.*;
import java.sql.*;

/**
 *
 * @author tkulbeth
 */
public class BackupServiceDAO {
    
    /** Contains an instance of MembershipDAO*/
    private static BackupServiceDAO instance = null; 
    
    /** Creates a new instance of BackupServiceDAO */
    public BackupServiceDAO() {
    }
    
    /**Retrieves an instance of the MembershipDAO object
     *
     * @return a current singleton instance of the MembershipDAO class
     */
    public static synchronized BackupServiceDAO getInstance() {
        if (instance == null) {
            instance = new BackupServiceDAO();
        }
        return instance;
    }    
    
    /** Reads in the one value from the Backup Service table for reference in the Backup functionality.
     *@return bs contains the backupServiceBO with the needed info.
     */
    public synchronized BackupServiceBO read() throws SQLException, ConnectionPoolException, DataException{
        BackupServiceBO bs = new BackupServiceBO();
        Connection conn = ConnectionPool.getInstance().get();
        PreparedStatement pstmt = conn.prepareStatement("Select * from Backup_Svc");
        
        ResultSet rs = pstmt.executeQuery();
        while(rs.next()){
            bs.setBuSvcID(rs.getString("BackupSvcID"));
            bs.setCurBuPrice(rs.getDouble("CurrentPrice"));
        }
        ConnectionPool.getInstance().release(conn);
        return bs;
    }
    
}
